//
//  ViewController.m
//  2.29
//
//  Created by student on 16/2/29.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIPageControl *pagecontroller;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIView *view1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 400, 400)];
    view1.backgroundColor=[UIColor redColor];
    UIView *view2=[[UIView alloc]initWithFrame:CGRectMake(400, 0, 400, 400)];
    view2.backgroundColor=[UIColor greenColor];
    UIView *view3=[[UIView alloc]initWithFrame:CGRectMake(400*2, 0, 400, 400)];
    view3.backgroundColor=[UIColor blueColor];
    UIScrollView *scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 200, 400, 400)];
    [scrollview addSubview:view1];
    [scrollview addSubview:view2];
    [scrollview addSubview:view3];
    
    scrollview.contentSize=CGSizeMake(400*3, 0);
    scrollview.bounces=YES;
    scrollview.indicatorStyle=UIScrollViewIndicatorStyleWhite;
    
//    scrollview.showsHorizontalScrollIndicator=NO;
//    scrollview.showsVerticalScrollIndicator=NO;
    
    scrollview.pagingEnabled=YES;
    
    scrollview.backgroundColor=[UIColor blackColor];
    [self.view addSubview:scrollview];
    scrollview.delegate=self;
    
    [self.view addSubview:self.pagecontroller];
    self.pagecontroller.numberOfPages=3;
    self.pagecontroller.currentPage=0;
    self.pagecontroller.pageIndicatorTintColor=[UIColor yellowColor];
    self.pagecontroller.currentPageIndicatorTintColor=[UIColor blackColor];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.pagecontroller.currentPage=scrollView.contentOffset.x/400;
}
@end
